166A - Rank List - CodeForces Solution


binary search implementation sortings *1100

Please click on ads to support us..

Python Code:

n, k = [int(i) for i in input().split()]

scores = []

for _ in range(n):
    p,t = [int(i) for i in input().split()]
    scores.append([p,t])

scores.sort(key= lambda x: x[1])
scores.sort(key = lambda x: x[0], reverse=True)


res = 0

for i in scores:
    if i == scores[k-1]:
        res +=1

print(res)

C++ Code:

///Bismillahir Rahmanir Rahim
///In the name of Allah

#include <bits/stdc++.h>
using namespace std;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define endl '\n'
/*
bool cmp( const pair<int, int> &p1, const pair<int, int> &p2)
{
    if(p1.first>p2.first) return 1;
    else if(p1.first == p2.first) return (p1.second<p2.second);
    return 0;
} */
int main()
{
    optimize();
    int n,k;
    cin>>n>>k;

    vector<pair<int, int>>v(n);

    for(int i=0;i<n;i++)
    {
        cin>>v[i].first>>v[i].second;
        v[i].first*=(-1); //without comparator
    }

    sort(v.begin(), v.end()); //without comparator

    int ans=0;

    for(auto u : v)
    {
        if(u==v[k-1]) ans++;
    }

    cout<<ans<<endl;

    return 0;
}


Comments

Submit
0 Comments
More Questions

174. Dungeon Game
127. Word Ladder
123. Best Time to Buy and Sell Stock III
85. Maximal Rectangle
84. Largest Rectangle in Histogram
60. Permutation Sequence
42. Trapping Rain Water
32. Longest Valid Parentheses
Cutting a material
Bubble Sort
Number of triangles
AND path in a binary tree
Factorial equations
Removal of vertices
Happy segments
Cyclic shifts
Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes